package com.itheima.stock.service.impl;

import com.itheima.stock.mapper.SysRoleMapper;
import com.itheima.stock.mapper.SysUserRoleMapper;
import com.itheima.stock.pojo.entity.SysRole;
import com.itheima.stock.pojo.entity.SysUser;
import com.itheima.stock.pojo.entity.SysUserRole;
import com.itheima.stock.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;
    @Autowired
    private SysRoleMapper roleMapper;

    @Override
    public List<SysRole> getRoleByUserId(Long userId) {
        List<Long> roleIds = sysUserRoleMapper.selectByUserId(userId);
        if(roleIds.size()!=0){
            List<SysRole> sysRoles = roleMapper.selectByPrimaryKeys(roleIds);
            return sysRoles;
        }
        return new ArrayList<>();
    }
}
